import {httpClient} from '@/utils/request';
import lark from '@/config';
import Cookies from 'js-cookie';
import {Utils} from '@/utils';

export async function rootFolder({type}) {
  const uuid = Cookies.get('uuid');
  return await httpClient.get({
    url: lark.env.api.DOCS.DRIVE.V1_ROOT_FOLDER,
    params: {
      uuid,
      type,
    },
  });
}


export async function folderChildren({folderToken, type}) {
  const uuid = Cookies.get('uuid');
  return await httpClient.get({
    url: lark.env.api.DOCS.DRIVE.V1_FOLDER_CHILDREN,
    params: {
      folderToken,
      uuid,
      type,
    },
  });
}

export async function uploadAll({formData, type}) {
  const uuid = Cookies.get('uuid');
  formData.append('uuid', uuid);
  return await httpClient.post({
    url: lark.env.api.DOCS.DRIVE.V1_FILES_UPLOAD_ALL,
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data; charset=utf-8',
      'Authorization': `Bearer ${Cookies.get('_hash')}`,
    },
    params: {
      type,
    },
  });
}

export async function createFolder({folderToken, title, type}) {
  const uuid = Cookies.get('uuid');
  const url = Utils.handleUrl(lark.env.api.DOCS.DRIVE.V1_FOLDER, folderToken);
  return await httpClient.post({
    url,
    params: {
      type,
      uuid,
    },
    data: {
      title,
    },
  });
}
